<template>
  <a-modal v-drag :destroyOnClose="true" :maskClosable="false" :centered="modal.centered" :width="modal.width"
    :visible="visible" :title="title" @cancel="cancel" :dialog-style="{ top: modal.top }" :bodyStyle="modal.bodyStyle">
    <a-spin :spinning="spinning">
      <a-card>
        <div>
          <a-skeleton :loading="skeleton">
            <k-form-build ref="kfb" v-if="!skeleton" :dynamicData="dynamicData" :defaultValue="defaultValue"
              :value="publicJson" :disabled="disabled" @change="handleChange" @complate="kfbComplate" />
          </a-skeleton>
        </div>
      </a-card>
      <a-card class="margin-top-xs" style="background: #fafafa" v-if="workflow.comment.length > 0">
        <div>
          <div style="margin-left: 20px">
            <a-timeline>
              <a-timeline-item v-for="(item, index) in workflow.comment" :key="index">
                <div slot="dot" :class="item.completedTime ? 'pointerItem' : 'pointerItem active'"></div>

                <div style="font-weight: 700;font-size:15px" :style="{ color: item.completedTime ? '#333' : '#1e88e5' }">
                  {{ item.receiveTime }}</div>
                <div class="padding workflowCard"
                  style="margin-top: 10px;background-color: #fff;border-radius: 5px; box-shadow: 0 1px 3px rgb(0 0 0 / 10%);">
                  <div style="font-size: 15px;font-weight: 700;" :style="{ color: item.completedTime ? '#333' : '#333' }">
                    {{ item.title
                    }}
                  </div>
                  <div class="flex justify-start align-center margin-top-xs">
                    <div>
                      <img style="width: 32px; height: 32px; border-radius: 50%" v-real-img="item.headImage" />
                    </div>
                    <div class="margin-left-xs">
                      <div style="font-size: 15px;color:#333;font-weight: 700">{{ item.receiveUserName }}
                        <label class="margin-left-xs" v-if="item.status == 16 && index != 0" style="color:#ff1e02">
                          拒绝</label>
                        <label class="margin-left-xs" v-if="item.status == 6 && index != 0" style="color:#4caf50">
                          通过</label>
                      </div>
                      <div style="font-size: 14px;color:#9e9e9e">{{ item.comment }}</div>
                    </div>
                  </div>
                  <div style="margin-left:30px">
                    <a-upload :file-list="item.files"> </a-upload>
                  </div>
                </div>
                <!-- <a-card size="small" style="margin-top: 10px" :hoverable="true">
                  <div slot="title">
                    <a-tag v-if="item.activityType == 2" color="#108ee9">
                      开始
                    </a-tag>

                    <a-tag v-if="item.activityType == 4" color="#87d068">
                      审批
                    </a-tag>

                    <a-tag v-if="item.activityType == 6" color="red">
                      子流程
                    </a-tag>

                    <a-tag v-if="item.activityType == 12" color="red">
                      知会
                    </a-tag>

                    <a-tag v-if="item.activityType == 14" color="red">
                      阅示
                    </a-tag>

                    <a-tag v-if="item.activityType == 16" color="red">
                      加签
                    </a-tag>

                    <a-tag v-if="item.activityType == 100" color="red">
                      结束
                    </a-tag>
                    {{ item.title }}
                  </div>
                  <div>发起时间: {{ item.receiveTime }}</div>
                  <div>发起人: {{ item.sendUserName }}</div>
                  <div>接收人: {{ item.receiveUserName }}</div>
                  <div>处理人: {{ item.doUserName }}</div>
                  <div>处理时间: {{ item.completedTime }}</div>
                  <div>
                    流程意见 {{ item.comment }}
                    <div>
                      <a-upload :file-list="item.files"> </a-upload>
                    </div>
                  </div>
                </a-card> -->
              </a-timeline-item>
            </a-timeline>
          </div>
        </div>
      </a-card>
      <!-- 督办审核历史 -->
      <a-card class="margin-top-xs" v-if="workflow.duBanHistory.length > 0">
        <div class="form">
          <div v-for="(his, index) in workflow.duBanHistory" :key="index" style="margin-top: 6px">
            <a-row type="flex">
              <a-col flex="auto">
                <a-avatar icon="user" />
                <label class="margin-left">【{{ his.doUserName }}】{{ his.comment }} <br /><a-upload :file-list="his.files">
                  </a-upload></label>
              </a-col>
              <a-col flex="200px">{{ his.completedTime }}</a-col>
            </a-row>
            <div class="margin-top invitationReadApproveDetail">
              【{{ his.approveUserName }}】 {{ his.approveTime }}
              <a-tag v-if="his.approveStatus == 0" color="#108ee9">
                通过
              </a-tag>

              <a-tag v-if="his.approveStatus == 1" color="#f5222d">
                拒绝
              </a-tag>
              <br />
              审核意见: {{ his.approveComment }}
            </div>
          </div>
        </div>
      </a-card>
      <!-- 阅示审批处理,有通过和拒绝按钮 -->
      <a-card class="margin-top-xs" v-if="workflowData.type == 6">
        <div>
          <div>
            <a-row type="flex">
              <a-col flex="auto">
                <a-avatar icon="user" />
                <label class="margin-left">{{
                  workflow.task.doUserName
                }}</label>
              </a-col>
              <a-col flex="200px">{{ workflow.task.completedTime }}</a-col>
            </a-row>
            <div class="margin-top invitationReadApproveDetail">
              {{ workflow.task.comment }}
              <a-upload :file-list="workflow.task.files"> </a-upload>
            </div>
          </div>
          <div class="margin-top">
            <label>审批意见</label>
            <div class="margin-top">
              <a-textarea placeholder="请输入流程意见" :rows="4" v-model="workflow.invitationreadApprove.comment" />
            </div>
          </div>
        </div>
      </a-card>
    </a-spin>
    <template slot="footer">
      <div class="flex justify-between align-center" v-if="!isWorkflow">
        <div>
          <a-checkbox v-if="!update" v-model="save.retain">
            继续创建时，保留本次提交内容
          </a-checkbox>
        </div>

        <a-space>
          <a-button v-if="!update" key="submit" @click="saveContinue" :loading="loading"><a-icon
              type="save" />提交并继续创建</a-button>
          <a-button v-if="update" @click="cancel"><a-icon type="close" />关闭</a-button>
          <a-button key="submit" @click="saveClose" type="primary" :loading="loading"><a-icon type="save" />提交</a-button>
        </a-space>
      </div>

      <div v-if="isWorkflow">
        <!-- 流程按钮 -->

        <a-space>
          <a-button key="back" @click="cancel" :disabled="loading">
            <a-icon type="close" />取消</a-button>
          <div>
            <!-- 若为审批 -->
            <template v-if="workflowData.type == 1">
              <a-space>
                <!-- <a-button
                  v-if="workflow.currentActivity.type == 'begin'"
                  @click="saveDraft"
                  type="primary"
                  :loading="loading"
                  ><a-icon type="container" />{{
                    workflow.draft.title
                  }}</a-button
                >
                <a-button
                  v-if="workflow.currentActivity.type == 'begin'"
                  @click="saveModel"
                  type="primary"
                  :loading="loading"
                  ><a-icon type="reconciliation" />{{
                    workflow.model.title
                  }}</a-button
                > -->

                <template v-if="workflow.props.button.length <= 8">
                  <a-tooltip v-for="(item, index) in workflow.props.button" :key="index">
                    <template slot="title">{{ item.name }}：{{ item.remark }}
                    </template>

                    <a-button @click="workflowButtonClick(item)" :type="item.type">
                      <a-icon :type="item.icon" /> {{ item.name }}
                    </a-button>
                  </a-tooltip></template>

                <template v-if="workflow.props.button.length > 8">
                  <a-tooltip v-for="(item, index) in workflow.props.button.slice(0, 8)" :key="index">
                    <template slot="title">{{ item.name }}：{{ item.remark }}
                    </template>

                    <a-button @click="workflowButtonClick(item)" :type="item.type">
                      <a-icon :type="item.icon" /> {{ item.name }}
                    </a-button>
                  </a-tooltip>
                </template>

                <a-popover placement="topRight" title="更多操作按钮" v-if="workflow.props.button.length > 8">
                  <template slot="content">
                    <a-space>
                      <a-tooltip v-for="(item, index) in workflow.props.button.slice(
                        8,
                        workflow.props.button.length
                      )" :key="index">
                        <template slot="title">{{ item.name }}：{{ item.remark }}
                        </template>

                        <a-button @click="workflowButtonClick(item)" :type="item.type">
                          <a-icon :type="item.icon" /> {{ item.name }}
                        </a-button>
                      </a-tooltip>
                    </a-space>
                  </template>
                  <a-button type="primary"><a-icon type="caret-up" /> 更多
                  </a-button>
                </a-popover>
              </a-space>
            </template>

            <!-- 知会处理 -->
            <template v-if="workflowData.type == 2">
              <a-space>
                <a-button type="primary" @click="workflowUnderStandingRead"><a-icon type="container" />已阅</a-button>
                <a-button type="primary" @click="
                  workflowButtonClick({ script: 'flowUnderstanding();' })
                "><a-icon type="reconciliation" />知会</a-button>
              </a-space>
            </template>

            <!-- 加签 -->
            <template v-if="workflowData.type == 3">
              <a-space>
                <a-button type="primary" @click="workflowAddApprove"><a-icon type="caret-right" />提交</a-button>
                <a-button type="primary" @click="workflowButtonClick({ script: 'flowAdd();' })"><a-icon
                    type="file-add" />加签</a-button>
                <a-button type="primary" @click="
                  workflowButtonClick({ script: 'flowUnderstanding();' })
                "><a-icon type="notification" />知会</a-button>
                <a-button type="primary" @click="workflowButtonClick({ script: 'flowDoList();' })"><a-icon
                    type="calendar" />过程列表</a-button>
                <a-button type="primary" @click="workflowButtonClick({ script: 'flowDesinger();' })"><a-icon
                    type="control" />流程图</a-button>
              </a-space>
            </template>

            <!-- 阅示处理 -->
            <template v-if="workflowData.type == 4">
              <a-space>
                <a-button type="primary" @click="
                  workflowButtonClick({
                    script: 'flowInvitationReadSure();',
                  })
                "><a-icon type="container" />已阅</a-button>
                <a-button type="primary" @click="
                  workflowButtonClick({ script: 'flowUnderstanding();' })
                "><a-icon type="reconciliation" />知会</a-button>
              </a-space>
            </template>

            <!-- 流程监控 -->
            <template v-if="workflowData.type == 5">
              <a-space>
                <a-button type="primary" @click="workflowButtonClick({ script: 'flowDoList();' })"><a-icon
                    type="calendar" />过程列表</a-button>
                <a-button type="primary" @click="workflowButtonClick({ script: 'flowDesinger();' })"><a-icon
                    type="control" />流程图</a-button>
              </a-space>
            </template>

            <!--  阅示审批处理,有通过和拒绝按钮 -->
            <template v-if="workflowData.type == 6">
              <a-space>
                <a-button type="primary" @click="workflowButtonClick({ script: 'flowDoList();' })"><a-icon
                    type="calendar" />过程列表</a-button>
                <a-button type="primary" @click="workflowButtonClick({ script: 'flowDesinger();' })"><a-icon
                    type="control" />流程图</a-button>

                <a-button v-if="workflow.task.status == 30" type="primary"
                  @click="workflowInvitationReadApprovePass"><a-icon type="check-circle" />通过</a-button>

                <a-button v-if="workflow.task.status == 30" type="primary"
                  @click="workflowInvitationReadApproveRefuse"><a-icon type="close-circle" />拒绝</a-button>
              </a-space>
            </template>
          </div>
        </a-space>

        <workflowHandleStart v-if="workflow.start.visible" :visible.sync="workflow.start.visible"
          :notice="workflow.sure.notice" :person="workflow.chosenPerson.data" @comfirm="workflowNextStartNotice">
        </workflowHandleStart>

        <workflowHandleRefuse v-if="workflow.refuse.visible" :visible.sync="workflow.refuse.visible"
          @comfirm="workflowRefuse">
        </workflowHandleRefuse>
        <workflowHandleSure :taskId="workflowData.taskId" v-if="workflow.sure.visible"
          :visible.sync="workflow.sure.visible" :notice="workflow.sure.notice" :person="workflow.chosenPerson.data"
          @comfirm="workflowTaskProcessSureComment">
        </workflowHandleSure>
        <workflowHandleEnd v-if="workflow.end.visible" :visible.sync="workflow.end.visible"
          @comfirm="workflowTaskProcessEndComment">
        </workflowHandleEnd>

        <workflowHandleReturn v-if="workflow.return.visible" :visible.sync="workflow.return.visible"
          :processInstanceId="workflow.form.processInstanceId" :taskId="workflowData.taskId" @comfirm="workflowReturn">
        </workflowHandleReturn>

        <workflowHandleReturnAndWrite v-if="workflow.returnandwrite.visible"
          :visible.sync="workflow.returnandwrite.visible" @comfirm="workflowReturnAndWrite">
        </workflowHandleReturnAndWrite>

        <workflowHandleUnderStandingStart v-if="workflow.understandingStart.visible"
          :visible.sync="workflow.understandingStart.visible" @comfirm="workflowUnderStandingStart">
        </workflowHandleUnderStandingStart>

        <workflowHandleUnderStanding v-if="workflow.understanding.visible" :visible.sync="workflow.understanding.visible"
          @comfirm="workflowUnderStanding">
        </workflowHandleUnderStanding>

        <workflowHandleInvitationRead v-if="workflow.invitationread.visible"
          :visible.sync="workflow.invitationread.visible" @comfirm="workflowInvitationRead">
        </workflowHandleInvitationRead>
        <workflowHandleInvitationReadSure v-if="workflow.invitationreadSure.visible"
          :visible.sync="workflow.invitationreadSure.visible" :taskId="workflowData.taskId"
          @comfirm="workflowInvitationReadSure">
        </workflowHandleInvitationReadSure>
        <workflowHandleInvitationReadApprove v-if="workflow.invitationreadApprove.visible"
          :visible.sync="workflow.invitationreadApprove.visible" :taskId="workflowData.taskId"
          @comfirm="workflowInvitationReadApprove">
        </workflowHandleInvitationReadApprove>
        <workflowHandleRevoke v-if="workflow.revoke.visible" :visible.sync="workflow.revoke.visible"
          @comfirm="workflowRevoke">
        </workflowHandleRevoke>

        <workflowHandleDeleteTask v-if="workflow.deleteTask.visible" :visible.sync="workflow.deleteTask.visible"
          @comfirm="workflowDeleteTask">
        </workflowHandleDeleteTask>

        <workflowHandleAdd v-if="workflow.add.visible" :visible.sync="workflow.add.visible" @comfirm="workflowAdd">
        </workflowHandleAdd>

        <workflowHandleDoList v-if="workflow.dolist.visible" :visible.sync="workflow.dolist.visible"
          :processInstanceId="workflow.form.processInstanceId">
        </workflowHandleDoList>
        <a-drawer width="100%" placement="right" :bodyStyle="{ padding: '1px' }" v-if="workflow.desinger.visible"
          title="流程监控" :visible="workflow.desinger.visible" @close="workflow.desinger.visible = false">
          <workflowDesinger v-if="workflow.desinger.visible" :processInstanceId="workflow.form.processInstanceId">
          </workflowDesinger>
        </a-drawer>
      </div>
    </template>
  </a-modal>
</template>

<script>
import moment from "moment";
import Vue from "vue";
import KFormDesign from "@/pages/system/agile/components/packages";
import "@/pages/system/agile/components/styles/form-design.less";

Vue.use(KFormDesign);

import { mapGetters } from "vuex";
import {
  businessData,
  businessDataById,
  businessDataBatch,
  businessDataFormSource,
  eventApi,
  fileCorrelationId,
  snQuery,
} from "@/services/system/agile/run/edit";

import {
  activityStart,
  workflowStart,
  workflowStartRun,
  workflowTaskProcess,
  workflowTaskProcessRun,
  workflowInstanceProcess,
  workflowActivityByTaskId,
  workflowTaskById,
  workflowEngineRefuse,
  workflowEngineReturnAndWrite,
  workflowEngineUnderStanding,
  workflowEngineUnderStandingRead,
  workflowEngineDraftSave,
  workflowEngineModelSave,
  workflowEngineInvitationRead,
  workflowEngineInvitationReadSure,
  workflowEngineInvitationReadApprove,
  workflowEngineInvitationReadApprovePass,
  workflowEngineInvitationReadApproveRefuse,
  workflowEngineRevoke,
  workflowEngineAdd,
  workflowEngineAddApprove,
  workflowEngineDeleteTask,
  workflowEngineDetail,
  workflowEngineEnd,
} from "@/services/workflow/send/index";
import { newGuid } from "@/utils/util";
import { request } from "@/utils/request";
import XEUtils from "xe-utils";
import { getAuthorization } from "@/utils/request";

import workflowHandleRefuse from "@/pages/workflow/handle/refuse";
import workflowHandleDoList from "@/pages/workflow/handle/dolist";
import workflowHandleReturnAndWrite from "@/pages/workflow/handle/returnandwrite";
import workflowHandleReturn from "@/pages/workflow/handle/return";
import workflowHandleUnderStandingStart from "@/pages/workflow/handle/understandingstart";
import workflowHandleUnderStanding from "@/pages/workflow/handle/understanding";
import workflowHandleInvitationRead from "@/pages/workflow/handle/invitationread";
import workflowHandleInvitationReadSure from "@/pages/workflow/handle/invitationreadSure";
import workflowHandleInvitationReadApprove from "@/pages/workflow/handle/invitationreadApprove";
import workflowHandleRevoke from "@/pages/workflow/handle/revoke";
import workflowHandleSure from "@/pages/workflow/handle/sure";
import workflowHandleEnd from "@/pages/workflow/handle/end";
import workflowHandleStart from "@/pages/workflow/handle/start";
import workflowHandleAdd from "@/pages/workflow/handle/add";
import workflowHandleDeleteTask from "@/pages/workflow/handle/delete";

import workflowDesinger from "@/pages/workflow/process/desinger";

export default {
  components: {
    workflowHandleInvitationRead,
    workflowHandleInvitationReadSure,
    workflowHandleInvitationReadApprove,
    workflowHandleRefuse,
    workflowHandleDoList,
    workflowHandleReturnAndWrite,
    workflowHandleReturn,
    workflowHandleUnderStandingStart,
    workflowHandleUnderStanding,
    workflowDesinger,
    workflowHandleRevoke,
    workflowHandleAdd,
    workflowHandleSure,
    workflowHandleStart,
    workflowHandleDeleteTask,
    workflowHandleEnd,
  },
  name: "start",
  computed: {
    ...mapGetters("account", ["user"]),
  },
  data() {
    return {
      relationTxt: "_Txt",
      height: this.eipHeaderHeight() - 48 + "px",
      modal: {
        top: "100px",
        centered: false,
        width: "400px",
        formWidth: "850px",
        bodyStyle: {
          padding: "1px",
        },
        button: {
          submit: {
            name: "保存",
            success: 0,
          },
        },
      },

      dynamicData: {}, //数据
      submitForm: {
        configId: null,
        relationId: newGuid(),
      },
      desingerFormValue: {}, //设计表单数据
      publicJson: {}, //当前表单配置
      columnJson: [], //表单项
      defaultValue: {},
      formValue: {}, //表单值

      spinning: false, //等待框loading
      loading: false, //按钮loading
      skeleton: false,

      dbType: "mysql", //数据库类型

      editConfig: {
        publicJson: "",
        columnJson: {},
      },
      save: {
        continue: false,
        retain: false,
      },
      workflow: {
        form: {
          extend: null,
          title: "",
          processId: this.workflowData.processId,
          processInstanceId: "",
          activityId: "", //开始流程节点
          formId: "", //表单Id
          json: "", //Json
          publicJson: "",
          activityType: "", //当前活动类型
          urgency: 0,
          comment: "", //处理意见
          notice: "", //通知数组
          taskId: null, //当前任务Id
        },

        rules: {
          title: [
            {
              required: true,
              message: "请输入流程标题",
            },
          ],
          comment: [
            {
              required: true,
              message: "请输入处理意见",
            },
          ],
        },

        currentActivity: {
          formId: null,
          publicJson: null,
          json: null,
          activityId: null,
          type: null,
        }, //当前活动

        submitValue: {}, //提交数据

        props: {
          button: [],
          column: [],
          notice: [],
          event: [],
          base: {
            titleruleTxt: "",
          },
        },

        comment: [], //流程历史意见

        chosenPerson: {
          //流程处理人
          visible: false,
          data: [],
          value: null,
        },

        //弹出框控制属性
        refuse: {
          visible: false,
        },
        sure: {
          visible: false,
          notice: [],
          noticeChosen: [],
        },
        start: {
          visible: false,
          notice: [],
        },
        returnandwrite: {
          visible: false,
        },
        dolist: {
          visible: false,
        },

        return: {
          visible: false,
        },

        desinger: {
          visible: false,
        },

        understandingStart: {
          visible: false,
        },

        understanding: {
          visible: false,
        },
        invitationread: {
          visible: false,
        },
        invitationreadSure: {
          visible: false,
        },
        invitationreadApprove: {
          visible: false,
          comment: null,
        },
        end: {
          visible: false,
          comment: null,
        },
        revoke: {
          visible: false,
        },
        add: {
          visible: false,
        },

        deleteTask: {
          visible: false,
        },

        draft: {
          title: "草稿箱",
        },

        model: {
          title: "范本夹",
        },

        //当前任务信息
        task: {
          activityId: undefined,
          activityType: undefined,
          comment: undefined,
          completedTime: undefined,
          customerData: undefined,
          doUserId: undefined,
          doUserName: undefined,
          extend: undefined,
          prevTaskId: undefined,
          processInstanceId: undefined,
          receiveTime: undefined,
          receiveUserId: undefined,
          receiveUserName: undefined,
          remark: undefined,
          sendUserId: undefined,
          sendUserName: undefined,
          status: undefined,
          taskId: undefined,

          files: [],
        },

        duBanHistory: [],
      },
    };
  },

  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    config: {
      type: Object,
      default: () => {
        return {
          editConfigId: undefined, //配置id
        };
      },
    },
    update: {
      type: Object,
      default: () => {
        return {
          RelationId: undefined, //配置id
        };
      },
    }, //编辑信息,如主键Id
    copy: {
      type: Boolean,
      default: false,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
    },

    //流程相关
    isWorkflow: {
      type: Boolean,
      default: false,
    }, //是否为工作流

    workflowData: {
      type: Object,
      default: () => {
        return {
          processId: undefined, //流程实例Id,发起流程时用
          processInstanceId: undefined,
          taskId: undefined,
          activityId: undefined,
          type: 1, //处理类型1审核，2知会，3加签，4阅示，5流程监控，6阅示审批处理,有通过和拒绝按钮
        };
      },
    },
  },

  mounted() {
    this.init();
  },
  methods: {
    /**
     * 取消
     */
    cancel() {
      this.$emit("update:visible", false);
    },

    /**
     * 所有控件值改变事件
     */
    handleChange(data) {
      var that = this;
      var columns = that.columnJson.filter((f) => f.model == data.key);
      that.formValue[data.key] = data.value;
      //查询与当前改变组件相关组件
      that.setMap(data);
      that.checkRelationData(data.key);
      that.checkReloadSource(data.key);
      //执行改变事件
      if (columns.length > 0 && columns[0].event && columns[0].event.change) {
        eval(columns[0].event.change);
      }
    },

    /**
     *
     */
    setMap(data) {
      let that = this;
      var columns = this.columnJson.filter((f) => f.model == data.key);
      var options = this.$refs.kfb.getOptions();
      if (columns.length > 0) {
        if (columns[0].type == "datalist") {
          var mapcolumns = columns[0].options.map.filter(
            (f) => f.mapcolumn != ""
          );
          mapcolumns.forEach((item) => {
            var values = options.filter((f) => f.model == data.key)[0].options
              .selectRows;
            var selectRowsValue = [];
            values.forEach((v) => {
              selectRowsValue.push(v[item.name]);
            });
            that.formValue[item.mapcolumn] = selectRowsValue.join(",");
          });
        }
      }
    },

    /**
     * 清空关联数据
     */
    checkRelationData(key) {
      var that = this;
      var columns = XEUtils.clone(that.columnJson, true);
      var dynamics = columns.filter(
        (f) =>
          f.options.dynamic &&
          f.options.dynamicConfig &&
          f.options.dynamicConfig.source &&
          f.options.dynamicConfig.source.condition &&
          f.options.dynamicConfig.source.condition.filter(
            (c) => c.condition == key
          ).length > 0
      );
      if (dynamics.length > 0) {
        dynamics.forEach((item) => {
          that.clearRelationData(item);
        });
      }
    },

    /**
     * 清空关联数据
     */
    clearRelationData(item) {
      this.$refs.kfb.setData({
        [item.model]: undefined,
      });
      this.checkRelationData(item.model);
    },

    /**
     * 根据传入的关键字获取关联数据
     * @param {*} key
     */
    checkReloadSource(key) {
      var that = this;
      var columns = XEUtils.clone(that.columnJson, true);
      var dynamics = columns.filter(
        (f) =>
          f.options.dynamic &&
          f.options.dynamicConfig &&
          f.options.dynamicConfig.source &&
          f.options.dynamicConfig.source.condition &&
          f.options.dynamicConfig.source.condition.filter(
            (c) => c.condition == key
          ).length > 0
      );
      if (dynamics.length > 0) {
        dynamics.forEach((item) => {
          that.reloadSource(item);
        });
      }
    },

    /**
     * 加载数据
     */
    reloadSource(item) {
      var that = this;
      //查看映射数据
      var fields = [];
      if (item.options.dynamicConfig.map.length > 0) {
      }

      //条件替换值
      var conditions = item.options.dynamicConfig.source.condition.filter(
        (f) => f.condition
      );
      conditions.forEach((citem) => {
        if (citem.condition.indexOf("'") == -1) {
          //将条件换为指具体值
          switch (citem.condition) {
            case "CreateUserId":
              citem.condition = that.user.userId;
              break;
            case "CreateUserName":
              citem.condition = that.user.name;
              break;
            case "CreateOrganizationId":
              citem.condition = that.user.organizationId;
              break;
            case "CreateOrganizationName":
              citem.condition = that.user.organizationName;
              break;
            default:
              citem.condition = that.formValue[citem.condition];
              break;
          }
        }
      });

      businessDataFormSource({
        table: item.options.dynamicConfig.source.name,
        key: item.options.dynamicConfig.key,
        value: item.options.dynamicConfig.value,
        filters: that.getWhereFilter(conditions),
        fields: fields.join(","),
        sidx: item.options.dynamicConfig.sidx, //排序字段
        sord: item.options.dynamicConfig.sord, //排序方式
      }).then(function (result) {
        if (result.code === that.eipResultCode.success) {
          let dynamicData = [];
          result.data.forEach((res) => {
            dynamicData.push({
              label: res[item.options.dynamicConfig.value],
              value: res[item.options.dynamicConfig.key],
            });
          });
          that.dynamicData[item.key] = dynamicData;
        }

        that.checkReloadSource(item.model);
      });
    },

    /**
     * 初始化设计器
     */
    async init() {
      let that = this;
      that.spinning = true;
      that.skeleton = true;
      //判断是流程还是普通表单
      debugger
      if (this.isWorkflow) {
        if (that.workflowData.processInstanceId) {
          that.workflow.form.processInstanceId =
            that.workflowData.processInstanceId;
          that.update.RelationId = that.workflowData.processInstanceId;
        }
        //是否具有流程任务Id
        if (this.workflowData.taskId) {
          var result = await workflowActivityByTaskId(that.workflowData.taskId);
          if (result.code == that.eipResultCode.success) {
            let data = result.data;
            if (data == null || data.length == 0) {
              that.$message.error("任务节点不存在,请确认是否被删除!!!");
              that.cancel();
            } else {
              that.workflow.currentActivity = data;
              if (that.workflow.currentActivity.json) {
                that.workflow.props = JSON.parse(
                  that.workflow.currentActivity.json
                ).props;

                that.workflow.props.button = that.workflow.props.button.filter(
                  (f) => f.showPc
                );
              }
              that.config.editConfigId = that.workflow.currentActivity.formId;
              that.workflow.currentActivity.type = "task";
              that.workflowCommentHistory();
            }
          }
        } else {
          if (that.workflowData.processInstanceId) {
            var result = await workflowEngineDetail({
              id: that.workflowData.processInstanceId,
            });
            debugger
            if (result.code == that.eipResultCode.success) {
              debugger
              let data = result.data;
              if (data == null || data.length == 0) {
                that.$message.error("任务节点不存在,请确认是否被删除!!!");
                that.cancel();
              } else {
                that.workflow.currentActivity = data;
                if (that.workflow.currentActivity.json) {
                  that.workflow.props = JSON.parse(
                    that.workflow.currentActivity.json
                  ).props;
                  that.workflow.props.button = that.workflow.props.button.filter(
                    (f) => f.showPc
                  );
                }
                that.config.editConfigId = that.workflow.currentActivity.formId;
                that.workflowCommentHistory();
              }
            }
          } else {
            //开始节点
            var result = await activityStart(that.workflowData.processId);
            if (result.code == that.eipResultCode.success) {
              let data = result.data;
              if (data == null || data.length == 0) {
                that.$message.error("未发现流程开始节点,请完善流程设置!!!");
                that.cancel();
              } else {
                that.workflow.currentActivity = data[0];
                if (that.workflow.currentActivity.json) {
                  that.workflow.props = JSON.parse(
                    that.workflow.currentActivity.json
                  ).props;
                  that.workflow.props.button = that.workflow.props.button.filter(
                    (f) => f.showPc
                  );
                }
                that.config.editConfigId = that.workflow.currentActivity.formId;
              }
            }
          }
        }
      }

      that.submitForm.configId = that.config.editConfigId;
      var result = await request(
        "/agile/" +
        that.config.editConfigId +
        ".txt?time=" +
        new Date().getTime(),
        {
          time: new Date().getTime(),
        }
      );
      that.editConfig = result;
      if (result.columnJson) {
        that.columnJson = JSON.parse(result.columnJson);
      }
      var publicJson = JSON.parse(that.editConfig.publicJson);
      that.modal.width =
        publicJson.config.width +
        (typeof publicJson.config.unit != "undefined"
          ? publicJson.config.unit
          : "px");
      that.modal.formWidth =
        publicJson.config.formWidth +
        (typeof publicJson.config.formWidthUnit != "undefined"
          ? publicJson.config.formWidthUnit
          : "px");

      that.modal.top = publicJson.config.top + "px";
      that.modal.centered = publicJson.config.centered;
      that.publicJson = publicJson;
      that.modal.button = publicJson.config.button;

      await that.initDynamicData();
      that.initUploadConfig();
      that.skeleton = false;

      //若是工作流
      if (that.isWorkflow) {
        that.workflowInit();
      } else {
        that.spinning = false;
      }
    },

    /**
     * 初始化文件上传配置
     */
    initUploadConfig() {
      let that = this;
      var uploadFile = this.getOptionsByType(["uploadFile", "uploadImg"]);
      uploadFile.forEach((item) => {
        const API_PROXY_PREFIX = "/api";
        const BASE_URL =
          process.env.NODE_ENV === "production"
            ? process.env.VUE_APP_API_BASE_URL
            : API_PROXY_PREFIX;
        item.options.action = BASE_URL + "/system/file/uploadform";
        item.options.data = JSON.stringify({
          correlationId: that.submitForm.relationId + "|" + item.model,
          issingle: !item.options.multiple,
        });
        var authorization = getAuthorization();
        item.options.headers = {
          Authorization: authorization,
        };
      });
      var wpsOption = this.getOptionsByType(["wps"]);
      wpsOption.forEach((item) => {
        const API_PROXY_PREFIX = "http://localhost:53604";
        const BASE_URL =
          process.env.NODE_ENV === "production"
            ? process.env.VUE_APP_API_BASE_URL
            : API_PROXY_PREFIX;
        item.options.action = BASE_URL + "/system/file/uploadform/wps";

        item.options.data = JSON.stringify({
          correlationId: that.submitForm.relationId + "|" + item.model,
          issingle: !item.options.multiple,
          userId: that.user.userId,
          title: "",
        });
      });
    },

    /**
     * 初始化数据源数据
     */
    async initDynamicData() {
      let that = this;
      var dynamicData = {};
      that.columnJson.forEach((item) => {
        if (item.options.dynamic) {
          dynamicData[item.key] = [];
        }
      });
      that.dynamicData = dynamicData;
      if (that.update && that.update.RelationId) {
        await that.find();
      } else {
        var value = {};
        await that.setDefaultValue(value);
        that.defaultValue = XEUtils.clone(value);
        that.formValue = value;
        //获取动态数据值
        await that.getDynamicData();
      }
    },

    /**
     * 获取数据
     */
    async getDynamicData(data) {
      let that = this;
      var columns = XEUtils.clone(that.columnJson, true);
      columns = columns.filter(
        (f) =>
          f.options.dynamic &&
          f.options.dynamicConfig &&
          f.options.dynamicConfig.source &&
          f.options.dynamicConfig.source.condition
      );
      for (let index = 0; index < columns.length; index++) {
        const item = columns[index];

        var fields = [];
        //查看映射数据
        if (item.options.dynamicConfig.map.length > 0) {
          item.options.dynamicConfig.map.forEach((item) => {
            fields.push(item.column);
          });
        }

        var conditions = item.options.dynamicConfig.source.condition.filter(
          (f) => f.condition
        );

        conditions.forEach((citem) => {
          if (citem.condition.indexOf("'") == -1) {
            if (data) {
              citem.condition = data[citem.condition];
            } else {
              //将条件换为指具体值
              switch (citem.condition) {
                case "CreateUserId":
                  citem.condition = that.user.userId;
                  break;
                case "CreateUserName":
                  citem.condition = that.user.name;
                  break;
                case "CreateOrganizationId":
                  citem.condition = that.user.organizationId;
                  break;
                case "CreateOrganizationName":
                  citem.condition = that.user.organizationName;
                  break;
                default:
                  citem.condition = that.formValue[citem.condition];
                  break;
              }
            }
          }
        });

        await businessDataFormSource({
          table: item.options.dynamicConfig.source.name,
          key: item.options.dynamicConfig.key,
          value: item.options.dynamicConfig.value,
          filters: that.getWhereFilter(conditions),
          fields: fields.join(","),
          sidx: item.options.dynamicConfig.sidx, //排序字段
          sord: item.options.dynamicConfig.sord, //排序方式
        }).then(function (result) {
          if (result.code === that.eipResultCode.success) {
            let dynamicData = [];
            result.data.forEach((res) => {
              dynamicData.push({
                label: res[item.options.dynamicConfig.value],
                value: res[item.options.dynamicConfig.key],
              });
            });
            that.dynamicData[item.key] = dynamicData;
          }
        });
      }
    },

    /**
     * 默认值
     */
    async setDefaultValue(defaultValue) {
      let that = this;
      //查看已有默认值配置
      //工作流需要在流程节点配置是否显示默认值
      if (this.isWorkflow) {
        var columns = this.workflow.props.column.filter((f) => f.isDefault);
        for (let index = 0; index < columns.length; index++) {
          const item = columns[index];
          //判断类型
          var column = that.columnJson.filter((f) => f.model == item.name);
          if (column.length > 0) {
            var config = column[0];
            var option = that.getOptionByModel(item.name);
            if (config.type == "user") {
              switch (config.options.defaultValueType) {
                case "username":
                  defaultValue[item.name] = that.user.name;
                  var chosen = [];
                  chosen.push({
                    id: that.user.userId,
                    name: that.user.name,
                  });
                  option.options.chosen = chosen;
                  break;
              }
            }

            if (config.type == "organization") {
              switch (config.options.defaultValueType) {
                case "orgname":
                  defaultValue[item.name] = that.user.organizationName;
                  var chosen = [];
                  chosen.push({
                    id: that.user.organizationId,
                    name: that.user.organizationName,
                  });
                  option.options.chosen = chosen;
                  break;
              }
            }

            //当前时间
            if (config.type == "date" && config.options.showTimeNow) {
              defaultValue[item.name] = moment(new Date()).format(
                config.options.format
              );
            }

            if (config.type == "input") {
              switch (config.options.defaultValueType) {
                case "billno":
                  var snQueryResult = await snQuery({
                    code: config.options.defaultValueBillNo,
                  });
                  defaultValue[item.name] = snQueryResult.data.value;
                  break;
                case "api":
                  var apiResult = await that.eventApiConfirm({
                    url: config.options.defaultValueApiPath,
                    type: 0,
                    param: JSON.stringify(defaultValue),
                  });
                  if (apiResult.code == that.eipResultCode.success) {
                    defaultValue[item.name] = apiResult.data;
                  }

                  break;
                case "userid":
                  defaultValue[item.name] = that.user.userId;
                  break;
                case "username":
                  defaultValue[item.name] = that.user.name;
                  break;
                case "orgid":
                  defaultValue[item.name] = that.user.organizationId;
                  break;
                case "orgname":
                  defaultValue[item.name] = that.user.organizationName;
                  break;
                case "shorttime":
                  defaultValue[item.name] = moment(new Date()).format(
                    "YYYY-MM-DD"
                  );
                  break;
                case "longtime":
                  defaultValue[item.name] = moment(new Date()).format(
                    "YYYY年MM月DD日"
                  );
                  break;
                case "shorttimemmhh":
                  defaultValue[item.name] = moment(new Date()).format("HH:mm");
                  break;
                case "longtimemmhh":
                  defaultValue[item.name] = moment(new Date()).format(
                    "HH时mm分"
                  );
                  break;
                case "shortdatetime":
                  defaultValue[item.name] = moment(new Date()).format(
                    "YYYY-MM-DD HH:mm"
                  );
                  break;
                case "longdatetime":
                  defaultValue[item.name] = moment(new Date()).format(
                    "YYYY年MM月DD日 HH时mm分"
                  );
                  break;
              }
            }
          }
        }
      } else {
        that.columnJson.forEach((item) => {
          if (item.options && item.options.defaultValue) {
            defaultValue[item.model] = item.options.defaultValue;
          }
        });
      }
    },

    /**
     * 查询数据
     */
    async find() {
      let that = this;
      var result = await businessDataById({
        configId: that.submitForm.configId,
        id: that.update.RelationId,
      });

      that.submitForm.relationId = that.update.RelationId;
      if (result.code == that.eipResultCode.success) {
        var value = {};
        var column = that.columnJson.filter(
          (f) =>
            f.layoutType != "batch" && f.type != "batch" && f.type != "text"
        );

        var array = column.filter((f) => !f.options.hidden);
        for (let index = 0; index < array.length; index++) {
          const item = array[index];
          switch (item.type) {
            case "select":
              if (item.options.multiple) {
                value[item.model] = result.data[item.model]?.split(",");
              } else {
                value[item.model] = result.data[item.model];
              }
              break;
            case "checkbox":
              value[item.model] = result.data[item.model]?.split(",");
              break;
            case "switch":
              value[item.model] =
                that.dbType == "mysql"
                  ? result.data[item.model] == 1
                  : result.data[item.model] == 0;
              break;
            case "user":
            case "post":
            case "dictionary":
            case "organization":
              var option = that.getOptionByModel(item.model);
              var ids = result.data[item.model];
              if (ids) {
                var chosen = [];
                var values = result.data[item.model + that.relationTxt].split(
                  ","
                );
                ids.split(",").forEach((item, index) => {
                  chosen.push({
                    id: item,
                    name: values[index],
                  });
                });
                option.options.chosen = chosen;
              }
              value[item.model] = result.data[item.model + that.relationTxt];
              break;
            case "uploadFile":
            case "uploadImg":
              var fileResult = await fileCorrelationId(
                that.submitForm.relationId + "|" + item.model
              );
              var uploads = [];
              fileResult.forEach((upload, index) => {
                uploads.push({
                  fileId: upload.fileId || "",
                  type: item.type == "uploadImg" ? "img" : "file",
                  name: upload.name,
                  status: "done",
                  uid: index,
                  url: upload.path || "",
                });
              });
              value[item.model] = uploads;
              break;
            case "wps":
              var fileResult = await fileCorrelationId(
                that.submitForm.relationId + "|" + item.model
              );
              value[item.model] = fileResult;
              break;
            default:
              value[item.model] = result.data[item.model];
              break;
          }
        }

        that.setDefaultValue(value);
        that.defaultValue = XEUtils.clone(value);
        column
          .filter((f) => f.options.hidden)
          .forEach((item) => {
            value[item.model] = result.data[item.model];
          });
        that.formValue = value;

        //得到联动数据
        await that.getDynamicData(result.data);

        //子表单
        var batchNames = [];
        that.columnJson
          .filter((f) => f.layoutType == "batch")
          .forEach((item) => {
            if (batchNames.indexOf(item.layoutTypeModel) == -1) {
              batchNames.push(item.layoutTypeModel);
            }
          });
        batchNames.forEach((batchItem, batchIndex) => {
          businessDataBatch({
            table: batchItem,
            id: result.data["RelationId"],
          }).then(function (result) {
            if (result.code == that.eipResultCode.success) {
              if (result.data && result.data.length > 0) {
                var values = [];

                //子表控件
                var columnBatchs = that.columnJson.filter(
                  (f) =>
                    f.layoutType == "batch" && f.layoutTypeModel == batchItem
                );

                result.data.forEach((ditem) => {
                  var value = {};
                  columnBatchs.forEach((item) => {
                    switch (item.type) {
                      case "checkbox":
                        value[item.model] = ditem[item.model]?.split(",");
                        break;
                      case "select":
                        if (item.options.multiple && ditem[item.model]) {
                          value[item.model] = ditem[item.model]?.split(",");
                        } else {
                          value[item.model] = ditem[item.model];
                        }
                        break;
                      case "switch":
                        value[item.model] =
                          that.dbType == "mysql"
                            ? ditem[item.model] == 1
                            : ditem[item.model] == 0;
                        break;
                      default:
                        value[item.model] = ditem[item.model];
                        break;
                    }
                  });
                  values.push(value);
                });
                //赋值
                that.$refs.kfb.setData({
                  [batchItem]: values,
                });
              }
            }
          });
        });
      } else {
        that.$message.destroy();
        that.$message.error(result.msg);
      }
    },

    /**
     * 保存流数据
     */
    async saveComfirm() {
      let that = this;
      await this.$refs.kfb
        .getData()
        .then(async (res) => {
          that.$message.loading("数据保存中");
          that.loading = true;
          that.$loading.show({ text: that.eipMsg.saveloading });
          var data = await that.getSubmiValue(res);
          var publicJson = JSON.parse(that.editConfig.publicJson);
          //判断是否具有提交前方法
          var event = publicJson.config.event;
          var eventResult = true;
          if (event.before) {
            eval(event.before);
          }
          if (eventResult) {
            //判断是否具有方法
            var api = publicJson.config.api;
            if (api.before) {
              var apiResult = await that.eventApiConfirm({
                url: api.before,
                param: JSON.stringify(data),
              });

              if (apiResult.code != that.eipResultCode.success) {
                that.loading = false;
                that.$loading.hide();
                that.$message.destroy();
                that.$message.error(apiResult.msg);
                return;
              }
            }
            businessData(data).then(async function (result) {
              that.loading = false;
              that.$loading.hide();
              that.$message.destroy();
              if (result.code == that.eipResultCode.success) {
                that.$message.success(result.msg);
                if (event.after) {
                  eval(event.after);
                }

                if (eventResult) {
                  if (api.after) {
                    var apiResult = await that.eventApiConfirm({
                      url: api.after,
                      param: JSON.stringify(data),
                    });

                    if (apiResult.code != that.eipResultCode.success) {
                      that.loading = false;
                      that.$loading.hide();
                      that.$message.destroy();
                      that.$message.error(apiResult.msg);
                      return;
                    }
                  }

                  if (that.update) {
                    that.cancel();
                  } else {
                    if (that.modal.button.submit.success == 0) {
                      if (that.save.continue) {
                        //不保留上次内容
                        if (!that.save.retain) {
                          that.$refs.kfb.reset();
                        }
                        that.submitForm.relationId = newGuid();
                      } else {
                        that.cancel();
                      }
                    }
                    if (that.modal.button.submit.success == 1) {
                      that.init();
                    }
                  }

                  that.$emit("ok", result);
                }
              } else {
                that.$message.error(result.msg);
              }
            });
          }
        })
        .catch((err) => {
          that.loading = false;
          that.$message.destroy();
        });
    },

    /**
     *
     */
    saveContinue() {
      this.save.continue = true;
      this.saveComfirm();
    },

    /**
     *
     */
    saveClose() {
      this.save.continue = false;
      this.saveComfirm();
    },

    /**
     *
     * @param {*} value
     */
    async eventApiConfirm(value) {
      var apiResult = await eventApi(value);
      return apiResult;
    },

    /**
     * 获取提交数据
     */
    getSubmiValue(res) {
      let that = this;
      let columns = [];
      var options = that.$refs.kfb.getOptions();
      options
        .filter(
          (f) =>
            f.layoutType != "batch" && f.type != "batch" && f.type != "text"
        )
        .forEach((columnObj) => {
          var value = that.formValue[columnObj.model];
          switch (columnObj.type) {
            case "checkbox":
              var txt = "";
              var txts = [];

              if (!value) {
                value = columnObj.options.defaultValue;
              }

              if (value) {
                value.forEach((v) => {
                  var option = columnObj.options.options.filter(
                    (f) => v == f.value
                  );
                  if (option.length > 0) {
                    txts.push(option[0].label);
                  }
                });
                value = value.join(",");
                txt = txts.join(",");
              }

              columns.push({
                issingle: false,
                name: columnObj.model,
                description: columnObj.label,
                type: columnObj.type,
                value: value,
              });

              columns.push({
                name: columnObj.model + that.relationTxt,
                description: columnObj.label,
                type: columnObj.type,
                value: txt,
              });

              break;
            case "radio":
              var txt = "";
              var txts = [];

              if (!value) {
                value = columnObj.options.defaultValue;
              }

              if (value) {
                var option = columnObj.options.options.filter(
                  (f) => value == f.value
                );
                if (option.length > 0) {
                  txts.push(option[0].label);
                }
                txt = txts.join(",");
              }

              columns.push({
                issingle: false,
                name: columnObj.model,
                description: columnObj.label,
                type: columnObj.type,
                value: value,
              });

              columns.push({
                name: columnObj.model + that.relationTxt,
                description: columnObj.label,
                type: columnObj.type,
                value: txt,
              });

              break;
            case "select":
              var txt = "";
              var options = columnObj.options.options;
              if (columnObj.options.dynamic) {
                options = that.dynamicData[columnObj.key];
              }

              if (columnObj.options.multiple && value) {
                var txts = [];
                value.forEach((v) => {
                  var option = options.filter((f) => v == f.value);
                  if (option.length > 0) {
                    txts.push(option[0].label);
                  }
                });
                txt = txts.join(",");
                //变成字符串并且用逗号分割
                value = value.join(",");
              } else {
                var option = options.filter((f) => f.value == value);
                if (option.length > 0) {
                  txt = option[0].label;
                }
              }

              columns.push({
                issingle: !columnObj.options.multiple,
                name: columnObj.model,
                description: columnObj.label,
                type: columnObj.type,
                value: value,
              });

              columns.push({
                name: columnObj.model + that.relationTxt,
                description: columnObj.label,
                type: columnObj.type,
                value: txt,
              });
              break;
            case "user":
            case "post":
            case "dictionary":
            case "organization":
              if (value) {
                columns.push({
                  issingle: !columnObj.options.multiple,
                  name: columnObj.model,
                  description: columnObj.label,
                  type: columnObj.type,
                  value: columnObj.options.chosen.map((m) => m.id).join(","),
                });

                columns.push({
                  name: columnObj.model + that.relationTxt,
                  description: columnObj.label,
                  type: columnObj.type,
                  value: value,
                });
              }

              break;
            case "switch":
              var c = {
                name: columnObj.model,
                description: columnObj.label,
                type: columnObj.type,
                value: null,
              };
              if (typeof value == "undefined") {
                //读取默认值
                c.value =
                  that.dbType == "mysql"
                    ? columnObj.options.defaultValue
                      ? 1
                      : 0
                    : columnObj.options.defaultValue
                      ? 0
                      : 1;
              } else {
                c.value =
                  that.dbType == "mysql" ? (value ? 1 : 0) : value ? 0 : 1;
              }
              columns.push(c);
              break;
            case "uploadFile":
            case "uploadImg":
            case "wps":
              break;
            default:
              columns.push({
                name: columnObj.model,
                description: columnObj.label,
                type: columnObj.type,
                value: value,
              });
              break;
          }
        });

      var batchNames = [],
        batchLabels = [];
      that.columnJson
        .filter((f) => f.layoutType == "batch")
        .forEach((item) => {
          if (batchNames.indexOf(item.layoutTypeModel) == -1) {
            batchNames.push(item.layoutTypeModel);
            batchLabels.push(item.layoutTypeLabel);
          }
        });

      batchNames.forEach((item, bindex) => {
        var value = res[item];
        var column = that.columnJson.filter(
          (f) => f.layoutTypeModel == item && f.layoutType == "batch"
        );
        var values = []; //值集合
        if (column != null && column.length > 0) {
          value.forEach((vf) => {
            var batchColumns = [];
            column.forEach((batchColumnObj) => {
              var batchValue = vf[batchColumnObj.model];
              switch (batchColumnObj.type) {
                case "radio":
                case "checkbox":
                  var txt = "";
                  if (batchValue) {
                    var txts = [];
                    batchValue.forEach((v) => {
                      var option = batchColumnObj.options.options.filter(
                        (f) => v == f.value
                      );
                      if (option.length > 0) {
                        txts.push(option[0].label);
                      }
                    });
                    txt = txts.join(",");
                    batchValue = batchValue.join(",");
                  }

                  batchColumns.push({
                    issingle: false,
                    name: batchColumnObj.model,
                    description: batchColumnObj.label,
                    type: batchColumnObj.type,
                    value: batchValue,
                  });

                  batchColumns.push({
                    name: batchColumnObj.model + that.relationTxt,
                    description: batchColumnObj.label,
                    type: batchColumnObj.type,
                    value: txt,
                  });

                  break;
                case "select":
                  var txt = "";
                  if (batchColumnObj.options.multiple && batchValue) {
                    var txts = [];
                    batchValue.forEach((v) => {
                      var option = batchColumnObj.options.options.filter(
                        (f) => v == f.value
                      );
                      if (option.length > 0) {
                        txts.push(option[0].label);
                      }
                    });
                    txt = txts.join(",");
                    //变成字符串并且用逗号分割
                    batchValue = batchValue.join(",");
                  } else {
                    var option = batchColumnObj.options.options.filter(
                      (f) => f.value == batchValue
                    );
                    if (option.length > 0) {
                      txt = option[0].lable;
                    }
                  }

                  batchColumns.push({
                    issingle: !batchColumnObj.options.multiple,
                    name: batchColumnObj.model,
                    description: batchColumnObj.label,
                    type: batchColumnObj.type,
                    value: batchValue,
                  });

                  batchColumns.push({
                    name: batchColumnObj.model + that.relationTxt,
                    description: batchColumnObj.label,
                    type: batchColumnObj.type,
                    value: txt,
                  });
                  break;
                case "user":
                case "post":
                case "dictionary":
                case "organization":
                  break;
                case "switch":
                  batchColumns.push({
                    name: batchColumnObj.model,
                    description: batchColumnObj.label,
                    type: batchColumnObj.type,
                    value:
                      that.dbType == "mysql"
                        ? batchValue
                          ? 1
                          : 0
                        : batchValue
                          ? 0
                          : 1,
                  });
                  break;
                default:
                  batchColumns.push({
                    name: batchColumnObj.model,
                    description: batchColumnObj.label,
                    type: batchColumnObj.type,
                    value: batchValue,
                  });
                  break;
              }
            });
            batchColumns.push({
              issingle: true,
              name: "BatchId",
              description: "子表主键",
              type: "hidden",
              value: newGuid(),
            });

            values.push({
              detail: batchColumns,
            });
          });
        }
        columns.push({
          name: item,
          description: batchLabels[bindex],
          type: "batch",
          value: JSON.stringify({
            table: item,
            values: values,
          }),
        });
      });

      return {
        configId: that.submitForm.configId,
        relationId: that.copy ? newGuid() : that.submitForm.relationId,
        columns: columns,
      };
    },

    /**
     *
     * 根据名称获取控件属性
     */
    getOptionByModel(model) {
      var option = null;
      // 递归遍历控件树
      const traverse = (array) => {
        array.forEach((element) => {
          if (model == element.model) {
            option = element;
          }
          if (element.type === "grid" || element.type === "tabs") {
            // 栅格布局 and 标签页
            element.columns.forEach((item) => {
              traverse(item.list);
            });
          } else if (element.type === "card" || element.type === "batch") {
            // 卡片布局 and  动态表格
            traverse(element.list);
          } else if (element.type === "table") {
            // 表格布局
            element.trs.forEach((item) => {
              item.tds.forEach((val) => {
                traverse(val.list);
              });
            });
          }
        });
      };
      traverse(this.publicJson.list);
      return option;
    },
    /**
     * 获取所有上传控件
     */
    getOptionsByType(types) {
      var files = [];
      // 递归遍历控件树
      const traverse = (array) => {
        array.forEach((element) => {
          if (types.indexOf(element.type) > -1) {
            files.push(element);
          }
          if (element.type === "grid" || element.type === "tabs") {
            // 栅格布局 and 标签页
            element.columns.forEach((item) => {
              traverse(item.list);
            });
          } else if (element.type === "card" || element.type === "batch") {
            // 卡片布局 and  动态表格
            traverse(element.list);
          } else if (element.type === "table") {
            // 表格布局
            element.trs.forEach((item) => {
              item.tds.forEach((val) => {
                traverse(val.list);
              });
            });
          }
        });
      };
      traverse(this.publicJson.list);
      return files;
    },
    /**
     * 获取条件
     */
    getWhereFilter(conditions) {
      var rules = "";
      conditions.forEach((item) => {
        if (item.pcrelation) {
          var searchColumn = item.name,
            searchOper = item.op,
            searchString = item.condition;
          if (searchColumn && searchOper) {
            rules +=
              ',{"field":"' +
              searchColumn +
              '","op":"' +
              searchOper +
              '","data":"' +
              searchString +
              '"}';
          }
        }
      });

      rules && (rules = rules.slice(1));
      var filtersStr = '{"groupOp":"AND","rules":[' + rules + "]}";
      return filtersStr;
    },
    /**
     * 保存到草稿箱
     */
    saveDraft() {
      let that = this;
      this.$refs.kfb.getData().then((res) => {
        that.$message.loading("数据保存中");
        that.loading = true;
        that.$loading.show({ text: that.eipMsg.saveloading });
        var data = that.getSubmiValue(res);
        //判断是否具有提交前方法
        businessData(data).then(function (result) {
          if (result.code == that.eipResultCode.success) {
            //保存到草稿箱
            that.workflow.form.activityType = "start";
            that.workflow.form.activityId =
              that.workflow.currentActivity.activityId;
            workflowEngineDraftSave(that.workflow.form).then((draftResult) => {
              if (draftResult.code == that.eipResultCode.success) {
                that.loading = false;
                that.$loading.hide();
                that.$message.destroy();
                that.workflow.draft.title = "更新草稿箱";
                that.$emit("ok", draftResult);
              }
            });
            that.$message.success(result.msg);
          } else {
            that.$message.error(result.msg);
          }
        });
      });
    },
    /**
     * 保存范本夹
     */
    saveModel() {
      let that = this;
      this.$refs.kfb.getData().then((res) => {
        that.$message.loading("数据保存中");
        that.loading = true;
        that.$loading.show({ text: that.eipMsg.saveloading });
        var data = that.getSubmiValue(res);
        //判断是否具有提交前方法
        businessData(data).then(function (result) {
          if (result.code == that.eipResultCode.success) {
            //保存范本夹
            that.workflow.form.activityType = "start";
            that.workflow.form.activityId =
              that.workflow.currentActivity.activityId;
            workflowEngineModelSave(that.workflow.form).then((draftResult) => {
              if (draftResult.code == that.eipResultCode.success) {
                that.loading = false;
                that.$loading.hide();
                that.$message.destroy();
                that.cancel();
                that.$emit("ok", draftResult);
              }
            });
            that.$message.success(result.msg);
          } else {
            that.$message.error(result.msg);
          }
        });
      });
    },

    /**
     * 初始化流程
     */
    async workflowInit() {
      let that = this;
      if (that.workflowData.type == this.eipWorkflowDoType["阅示审批"]) {
        var taskResult = await workflowTaskById(that.workflowData.taskId);
        if (taskResult.code == that.eipResultCode.success) {
          this.workflow.task.doUserName = taskResult.data.doUserName;
          this.workflow.task.completedTime = taskResult.data.completedTime;
          this.workflow.task.comment = taskResult.data.comment;
          this.workflow.task.status = taskResult.data.status;
        }

        //获取相关附件
        var fileResult = await fileCorrelationId(that.workflowData.taskId);
        var uploads = [];
        fileResult.forEach((upload, index) => {
          uploads.push({
            fileId: upload.fileId || "",
            type: "file",
            name: upload.name,
            status: "done",
            uid: index,
            url: upload.path || "",
          });
        });
        that.workflow.task.files = uploads;

        //得到历史阅示信息
        workflowInstanceProcess({
          id: this.workflowData.processInstanceId,
        }).then(async (result) => {
          var datas = result.data.filter(
            (f) =>
              f.title == "督办" &&
              f.doUserId == taskResult.data.receiveUserId &&
              f.taskId != that.workflowData.taskId
          );
          datas.forEach((item) => {
            item.files = [];
          });

          datas
            .filter((f) => f.status == 6)
            .forEach(async (item) => {
              var fileResult = await fileCorrelationId(item.taskId);
              var uploads = [];
              fileResult.forEach((upload, index) => {
                uploads.push({
                  fileId: upload.fileId || "",
                  type: "file",
                  name: upload.name,
                  status: "done",
                  uid: index,
                  url: upload.path || "",
                });
              });
              item.files = uploads;
            });
          that.workflow.duBanHistory = datas;
        });
      } else {
        //开始节点
        if (!that.workflowData.processInstanceId) {
          that.workflow.form.processInstanceId = that.submitForm.relationId;
        }
      }
      this.workflowNotice();
      that.spinning = false;
    },

    /**
     * 按钮点击
     */
    async workflowButtonClick(button) {
      switch (button.script) {
        case "flowSave();": //保存数据
          this.workflowSave(this.workflowLoadingHide);
          break;
        case "flowNext();": //保存数据
          this.workflowNext();
          break;

        case "flowReturn();": //退回
          this.workflow.return.visible = true;
          break;
        case "flowRefuse();": //拒绝
          this.workflow.refuse.visible = true;
          break;
        case "flowDoList();": //过程列表
          this.workflow.dolist.visible = true;
          break;
        case "flowReturnAndWrite();": //退回重填
          this.workflow.returnandwrite.visible = true;
          break;
        case "flowDesinger();": //流程图
          this.workflow.desinger.visible = true;
          break;
        case "flowUnderstanding();": //知会
          switch (this.workflow.currentActivity.type) {
            case "begin":
              this.workflow.understandingStart.visible = true;
              break;
            case "task":
              this.workflow.understanding.visible = true;
              break;
          }
          break;
        case "flowUnderstandingSure();": //知会阅示直接结束
          this.workflowUnderStandingRead();
          break;
        case "flowInvitationRead();": //邀请阅示
          this.workflow.invitationread.visible = true;
          break;
        case "flowInvitationReadSure();": //邀请阅示确定,弹出意见框
          this.workflow.invitationreadSure.visible = true;
          break;
        case "flowInvitationReadApprove();": //邀请阅示确定,弹出意见框
          this.workflow.invitationreadApprove.visible = true;
          break;
        case "flowRevoke();": //撤销
          this.workflow.revoke.visible = true;
          break;
        case "flowEnd();": //结束
          this.workflow.end.visible = true;
          break;
        case "flowAdd();": //加签
          this.workflow.add.visible = true;
          break;
        case "flowDelete();": //删除
          this.workflow.deleteTask.visible = true;
          break;
      }

      // let that = this;
      // button.script = "that." + button.script;
      // eval(button.script);
    },

    /**
     * 生成流程标题
     */
    workflowGenerateTitleRule(data) {
      var title = "";
      let that = this;
      var titleRule = that.workflow.props.base.titleruleTxt;
      if (titleRule != null) {
        var rules = titleRule.split("{");
        rules.forEach((item) => {
          if (item.indexOf("}") > 0) {
            //判断值
            var reg = item.split("}");
            reg.forEach((r) => {
              switch (r) {
                case "流程类型名称":
                  title += currentActivity.ProcessName;
                  break;
                case "当前时间":
                  title += moment().format("YYYY-MM-DD HH:mm:ss");
                  break;
                case "当前用户组织架构名称":
                  title += that.user.organizationName;
                  break;
                case "当前用户名":
                  title += that.user.name;
                  break;
                default:
                  //是否具有[]
                  if (r.indexOf("表单字段") >= 0) {
                    var column = r.replace("表单字段", "");
                    var searchColumns = data.columns.filter(
                      (f) => f.name == column
                    );
                    if (searchColumns.length > 0) {
                      title += searchColumns[0].value;
                    }
                  } else {
                    title += r;
                  }
              }
            });
          } else {
            title += item;
          }
        });
      }

      this.workflow.form.title = title;
    },

    /**
     *流程保存
     */
    async workflowSave(method) {
      let that = this;
      await that.$refs.kfb
        .getData()
        .then(async (res) => {
          var eventResult = true;
          var events = that.workflow.props.event.filter(
            (f) => f.use && f.trigger == 0 && f.type == 0
          );
          events.forEach((item) => {
            eval(item.config.js);
          });
          if (eventResult) {
            that.desingerFormValue = res;
            that.$loading.show({ text: that.eipMsg.saveloading });
            var data = that.getSubmiValue(res);
            var result = await businessData(data);
            if (that.workflow.currentActivity.type == "begin") {
              that.workflowGenerateTitleRule(data);
            }
            if (result.code == that.eipResultCode.success) {
              that.$message.success("保存成功");
              method();
              that.$emit("ok", result);
            } else {
              that.$message.error(result.msg);
            }
          }
        })
        .catch((err) => { });
    },

    /**
     * 流程处理完毕关闭弹出层
     */
    workflowLoadingHide() {
      this.$message.destroy();
      this.$loading.hide();
    },

    /**
     * 下一步
     */
    workflowNext() {
      //判断是开始节点还是处理节点
      switch (this.workflow.currentActivity.type) {
        case "begin":
          this.workflowNextStart();
          break;
        case "task":
          this.workflowTaskProcessSure();
          break;
      }
    },

    /**
     * 流程开始
     */
    async workflowNextStart() {
      let that = this;
      await that.$refs.kfb.getData().then(async (res) => {
        that.workflow.form.notice = that.workflow.sure.noticeChosen.join(",");
        that.workflow.form.activityType = "start";
        that.workflow.form.activityId = that.workflow.currentActivity.activityId;
        that.$loading.show({ text: "处理中..." });
        var data = await that.getSubmiValue(res);
        that.workflow.form.columns = data.columns
        workflowStart(that.workflow.form).then(async (result) => {
          if (result.code == that.eipResultCode.success) {
            that.workflow.form.activities = result.data.activities;
            that.workflow.form.links = result.data.links;
            that.workflow.form.needChosenPerson = result.data.needChosenPerson;
            let nextTask = [], //任务处理人
              chosenPerson = false, //是否具有弹出处理人
              chosenPersons = []; //弹出选择处理人
            result.data.person.forEach((item) => {
              let activity = item.activity; //返回下个步骤处理人
              var activityObj = JSON.parse(activity.json);
              if (activityObj.props.user) {
                //处理策略：0列表中的第一处理人，1发送给列表中的所有处理人，2弹出选择审批人
                switch (activityObj.props.user.strategy) {
                  case 2: //弹出选择审批人
                    chosenPerson = true;
                    chosenPersons.push(item);
                    break;
                  default:
                    nextTask.push({
                      activity: {
                        title: activityObj.text.text,
                        processInstanceId: activity.processInstanceId,
                        activityId: activity.activityId,
                        type: activity.type,
                        json: activity.json,
                        // subprocessinput: activity.SubProcessInput,
                        // subprocessoutput: activity.SubProcessOutput,
                        // subProcessProcessId: activity.SubProcessProcessId
                      },
                      persons: item.persons,
                    });
                    break;
                }
              } else {
                nextTask.push({
                  activity: {
                    title: activityObj.text.text,
                    processInstanceId: activity.processInstanceId,
                    activityId: activity.activityId,
                    type: activity.type,
                    json: activity.json,
                    // subprocessinput: activity.SubProcessInput,
                    // subprocessoutput: activity.SubProcessOutput,
                    // subProcessProcessId: activity.SubProcessProcessId
                  },
                  persons: item.persons,
                });
              }
            });

            //判断是否跳转到选择人人员出来界面
            if (chosenPerson) {
              that.workflowLoadingHide();
              chosenPersons.forEach((item) => {
                item.checked = false;
              });
              that.workflow.chosenPerson.data = chosenPersons;
              that.workflow.chosenPerson.visible = true;
              that.workflow.start.visible = true;
            } else {
              that.workflow.form.nextTask = nextTask;
              that.workflow.form.nextTaskString = JSON.stringify(nextTask);
              //是否需要弹出通知方式,若不弹出则直接走下一步
              if (that.workflow.form.notice) {
                that.workflowLoadingHide();
                that.workflow.start.visible = true;
              } else {
                that.workflowSave(that.workflowStartNextTask);
              }
            }
          } else {
            that.workflowLoadingHide();
            that.$message.error(result.msg);
            return success({
              result: false,
            });
          }
        });
      });
    },
    /**
     * 选择通知后事件
     * @param {*} data
     */
    workflowNextStartNotice(data) {
      this.workflow.sure.noticeChosen = data.notice;
      this.workflow.chosenPerson.value = data.person;
      if (this.workflow.chosenPerson.visible) {
        this.workflowChosenPersonComfirm();
      } else {
        this.$loading.show({ text: this.eipMsg.saveloading });
        this.workflowNextStart();
      }
    },

    /**
     * 开始下一步
     * @param {Object} that
     * @param {Object} data
     * @param {Object} success
     */
    workflowStartNextTask() {
      let that = this;
      that.$loading.show({ text: "处理中..." });
      this.workflow.form.notice = this.workflow.sure.noticeChosen.join(",");
      //保存业务数据
      workflowStartRun(this.workflow.form).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.$emit("ok", result);
          that.cancel();
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     * 设置默认通知
     */
    workflowNotice() {
      this.workflow.sure.notice = this.workflow.props.notice.filter(
        (f) => f.use && f.trigger == 0 && f.userchosen
      );
      var notice = [];
      for (let index = 0; index < this.workflow.sure.notice.length; index++) {
        notice.push(index);
      }
      this.workflow.sure.noticeChosen = notice;
      this.workflow.form.notice = notice.join(",");
    },

    /**
     * 输入意见后提交
     * @param {*} data
     */
    workflowTaskProcessSureComment(data) {
      this.workflow.form.comment = data.comment;
      this.workflow.sure.noticeChosen = data.notice;
      this.workflow.chosenPerson.value = data.person;

      if (this.workflow.chosenPerson.visible) {
        this.workflowChosenPersonComfirm();
      } else {
        this.$loading.show({ text: this.eipMsg.saveloading });
        this.workflowTaskProcessTask();
      }
    },

    /**
     * 确定流程走向
     */
    async workflowTaskProcessSure() {
      let that = this;
      await that.$refs.kfb.getData().then(async (res) => {
        that.loading = true;
        that.$loading.show({ text: "处理中..." });
        that.workflow.form.activityType = "task";
        that.workflow.form.activityId = that.workflow.currentActivity.activityId;
        that.workflow.form.taskId = that.workflowData.taskId;
        that.workflow.form.notice = that.workflow.sure.noticeChosen.join(",");
        var data = await that.getSubmiValue(res);
        that.workflow.form.columns = data.columns
        workflowTaskProcess(that.workflow.form).then(async (result) => {
          if (result.code == that.eipResultCode.success) {
            that.workflow.form.activities = result.data.activities;
            that.workflow.form.links = result.data.links;
            that.workflow.form.needChosenPerson = result.data.needChosenPerson;
            let nextTask = [], //任务处理人
              chosenPerson = false, //是否具有弹出处理人
              chosenPersons = []; //弹出选择处理人
            result.data.person.forEach((item) => {
              let activity = item.activity; //返回下个步骤处理人
              var activityObj = JSON.parse(activity.json);
              if (activityObj.props.user) {
                switch (activityObj.props.user.strategy) {
                  case 2: //弹出选择审批人
                    chosenPerson = true;
                    chosenPersons.push(item);
                    break;
                  default:
                    nextTask.push({
                      activity: {
                        title: activityObj.text.text,
                        processInstanceId: activity.processInstanceId,
                        activityId: activity.activityId,
                        type: activity.type,
                        json: activity.json,
                        // subprocessinput: activity.SubProcessInput,
                        // subprocessoutput: activity.SubProcessOutput,
                        // subProcessProcessId: activity.SubProcessProcessId
                      },
                      persons: item.persons,
                    });
                    break;
                }
              } else {
                nextTask.push({
                  activity: {
                    title: activityObj.text.text,
                    processInstanceId: activity.processInstanceId,
                    activityId: activity.activityId,
                    type: activity.type,
                    json: activity.json,
                    // subprocessinput: activity.SubProcessInput,
                    // subprocessoutput: activity.SubProcessOutput,
                    // subProcessProcessId: activity.SubProcessProcessId
                  },
                  persons: item.persons,
                });
              }
            });

            //判断是否跳转到选择人人员出来界面
            if (chosenPerson) {
              //弹出人员
              that.workflowLoadingHide();
              chosenPersons.forEach((item) => {
                item.checked = false;
              });
              that.workflow.chosenPerson.data = chosenPersons;
              that.workflow.sure.visible = true;
              that.workflow.chosenPerson.visible = true;
            } else {
              that.workflow.form.nextTask = nextTask;
              that.workflow.form.nextTaskString = JSON.stringify(nextTask);
              //是否需要弹出通知方式,若不弹出则直接走下一步
              if (
                that.workflow.form.notice ||
                that.workflow.props.base.commentstype != 0
              ) {
                that.workflowLoadingHide();
                that.workflow.sure.visible = true;
              } else {
                that.workflowSave(that.workflowTaskProcessTask);
              }
            }
          } else {
            that.workflowLoadingHide();
            that.$message.error(result.msg);
            return success({
              result: false
            });
          }
        });
      })
    },
    /**
     * 开始下一步
     * @param {Object} that
     * @param {Object} data
     * @param {Object} success
     */
    workflowTaskProcessTask() {
      let that = this;
      this.$loading.show({ text: "处理中..." });
      workflowTaskProcessRun(this.workflow.form).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     * 选择人员确定
     */
    async workflowChosenPersonComfirm() {
      let that = this;
      var checked = that.workflow.chosenPerson.value;
      //查看是否选择了人员
      var nextTask = [];
      this.workflow.chosenPerson.data.forEach((item) => {
        let activity = item.activity; //返回下个步骤处理人
        var activityObj = JSON.parse(activity.json);
        var task = {
          activity: {
            title: activityObj.text.text,
            processInstanceId: activity.processInstanceId,
            activityId: activity.activityId,
            type: activity.type,
            json: activity.json,
            // subprocessinput: activity.SubProcessInput,
            // subprocessoutput: activity.SubProcessOutput,
            // subProcessProcessId: activity.SubProcessProcessId
          },
          persons: [],
        };
        item.persons.forEach((pitem) => {
          var isIn = false;
          //是否为字符串
          if (typeof checked == "string") {
            isIn = checked == pitem.userId;
          } else {
            isIn = checked.filter((f) => f == pitem.userId).length > 0;
          }
          if (isIn) {
            task.persons.push({
              userId: pitem.userId,
              code: pitem.code,
              name: pitem.name,
            });
          }
        });
        if (task.persons.length > 0) {
          nextTask.push(task);
        }
      });
      if (nextTask.length == 0) {
        that.$message.error("请选择流程处理人");
        return;
      }
      that.workflow.form.nextTask = nextTask;
      that.workflow.form.nextTaskString = JSON.stringify(nextTask);
      if (this.workflow.form.activityType == "start") {
        //重新赋予处理人员
        that.workflowSave(that.workflowStartNextTask);
      } else {
        that.workflowSave(that.workflowTaskProcessTask);
      }
    },

    /**
     * 初始化历史意见
     */
    async workflowCommentHistory() {
      let that = this;
      if (that.workflow.props.base.isopinion) {
        workflowInstanceProcess({
          id: this.workflowData.processInstanceId,
        }).then(async (result) => {
          result.data.forEach((item) => {
            item.files = [];
          });
          result.data.forEach(async (item) => {
            var fileResult = await fileCorrelationId(item.taskId);
            var uploads = [];
            fileResult.forEach((upload, index) => {
              uploads.push({
                fileId: upload.fileId || "",
                type: "file",
                name: upload.name,
                status: "done",
                uid: index,
                url: upload.path || "",
              });
            });
            item.files = uploads;
          });
          that.workflow.comment = result.data;
        });
      }
    },

    /**
     *
     */
    workflowTaskProcessEndComment(data) {
      this.workflow.end.comment = data.comment;
      this.$message.loading("数据保存中");
      this.loading = true;
      this.$loading.show({ text: this.eipMsg.saveloading });
      this.workflowEnd();
    },

    /**
     *
     */
    workflowEnd() {
      let that = this;
      //提示
      workflowEngineEnd({
        taskId: that.workflowData.taskId,
        comment: that.workflow.end.comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     *加签
     */
    workflowAdd(data) {
      let that = this;
      that.$loading.show({ text: "加签中.." });
      this.workflow.form.extend = data;
      switch (this.workflow.currentActivity.type) {
        case "begin":
          this.workflow.form.activityType = "start";
          break;
        case "task":
          this.workflow.form.activityType = "task";
          break;
      }
      this.workflow.form.activityId = that.workflow.currentActivity.activityId;
      this.workflow.form.taskId = that.workflowData.taskId;
      workflowEngineAdd(this.workflow.form).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     *
     */
    workflowAddApprove() {
      let that = this;
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.$loading.show({ text: "处理中.." });
          workflowEngineAddApprove({
            taskId: that.workflowData.taskId,
            comment: that.workflow.form.comment,
          }).then((result) => {
            that.workflowLoadingHide();
            if (result.code == that.eipResultCode.success) {
              that.$message.success(result.msg);
              that.cancel();
              that.$emit("ok", result);
            } else {
              that.$message.error(result.msg);
            }
          });
        }
      });
    },

    /**
     * 拒绝
     */
    workflowRefuse(comment) {
      let that = this;
      that.$loading.show({ text: "任务拒绝中.." });
      workflowEngineRefuse({
        taskId: this.workflowData.taskId,
        comment: comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     * 删除
     * @param {*} comment
     */
    workflowDeleteTask(comment) {
      let that = this;
      that.$loading.show({ text: "删除中.." });
      workflowEngineDeleteTask({
        taskId: this.workflowData.taskId,
        comment: comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     * 返回重填
     * @param {*} comment
     */
    workflowReturnAndWrite(comment) {
      let that = this;
      that.$loading.show({ text: "返回重填中.." });
      workflowEngineReturnAndWrite({
        taskId: this.workflowData.taskId,
        comment: comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     *
     */
    workflowUnderStandingStart(data) { },

    /**
     *
     */
    workflowUnderStanding(data) {
      let that = this;
      that.$loading.show({ text: "处理中.." });
      workflowEngineUnderStanding({
        taskId: this.workflowData.taskId,
        userId: data.userId,
        userName: data.userName,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },
    /**
     *
     */
    workflowUnderStandingRead() {
      let that = this;
      that.$loading.show({ text: "处理中.." });
      workflowEngineUnderStandingRead({
        taskId: that.workflowData.taskId,
        comment: that.workflow.form.comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     *
     */
    workflowInvitationRead(data) {
      let that = this;
      that.$loading.show({ text: "处理中.." });
      workflowEngineInvitationRead({
        taskId: this.workflowData.taskId,
        userId: data.userId,
        userName: data.userName,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     *
     */
    workflowInvitationReadSure(comment) {
      let that = this;
      that.$loading.show({ text: "处理中.." });
      workflowEngineInvitationReadSure({
        taskId: that.workflowData.taskId,
        comment: comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     *
     */
    workflowInvitationReadApprove(comment) {
      let that = this;
      that.$loading.show({ text: "处理中.." });
      workflowEngineInvitationReadApprove({
        taskId: that.workflowData.taskId,
        comment: comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     *
     * @param {*} comment
     */
    workflowRevoke(comment) {
      let that = this;
      that.$loading.show({ text: "撤销中.." });
      workflowEngineRevoke({
        taskId: this.workflowData.taskId,
        comment: comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },
    /**
     * 退回某步
     * @param {*} comment
     */
    workflowReturn(data) {
      let that = this;
      that.$loading.show({ text: "退回中.." });
      workflowEngineReturnAndWrite({
        taskId: this.workflowData.taskId,
        activityId: data.activityId,
        comment: data.comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     * 审核通过
     */
    workflowInvitationReadApprovePass() {
      let that = this;
      that.$loading.show({ text: "通过中.." });
      workflowEngineInvitationReadApprovePass({
        taskId: this.workflowData.taskId,
        comment: this.workflow.invitationreadApprove.comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     * 审核拒绝
     */
    workflowInvitationReadApproveRefuse() {
      let that = this;
      if (!this.workflow.invitationreadApprove.comment) {
        this.$message.error("请输入拒绝理由");
        return;
      }
      that.$loading.show({ text: "拒绝中.." });
      workflowEngineInvitationReadApproveRefuse({
        taskId: this.workflowData.taskId,
        comment: this.workflow.invitationreadApprove.comment,
      }).then((result) => {
        that.workflowLoadingHide();
        if (result.code == that.eipResultCode.success) {
          that.$message.success(result.msg);
          that.cancel();
          that.$emit("ok", result);
        } else {
          that.$message.error(result.msg);
        }
      });
    },

    /**
     * 流程字段:控制隐藏显示
     */
    workflowColumn() {
      var hides = [],
        disableds = [];
      this.workflow.props.column.forEach((item) => {
        if (item.isHide) {
          hides.push(item.name);
        }
        if (!item.isWrite) {
          disableds.push(item.name);
        }
      });
      //判断当前步骤名称
      if (hides.length > 0) {
        this.$refs.kfb.hide(hides);
      }
      if (disableds.length > 0) {
        this.$refs.kfb.disable(disableds);
      }

      var rules = this.workflow.props.column.filter(
        (f) => f.validator.length > 0
      );
      if (rules.length > 0) {
        this.$refs.kfb.rule(rules);
      }
    },

    /**
     * 组件加载完成
     */
    async kfbComplate() {
      let that = this;
      if (
        this.workflowData.type == this.eipWorkflowDoType["流程监控"] ||
        this.workflowData.type == this.eipWorkflowDoType["阅示审批"]
      ) {
        this.$refs.kfb.disable(this.workflow.props.column.map((m) => m.name));
      } else {
        this.workflowColumn();
      }

      if (this.workflowData.processInstanceId) {
        /**
         * 公文系统-特殊判断
         */
        if (this.workflow.currentActivity.json) {
          var json = JSON.parse(this.workflow.currentActivity.json);
          if (json.text.text == "督办" || json.text.text == "传阅") {
            var parent = $(".kk-table-9136076486841527").parent();
            $(parent)
              .next()
              .attr("class", "grid-col ant-col ant-col-24");
            $(parent).remove();
          }
        }
      }

      //特殊判断
      if (this.workflow.props.base.title == "督办") {
        //获取上一节点
        workflowInstanceProcess({
          id: this.workflowData.processInstanceId,
        }).then(async (result) => {
          var datas = result.data.filter(
            (f) => f.title == "督办" && f.doUserId == this.user.userId
          );
          console.log(result);
          datas.forEach((item) => {
            item.files = [];
          });

          datas
            .filter((f) => f.status == 6)
            .forEach(async (item) => {
              var fileResult = await fileCorrelationId(item.taskId);
              var uploads = [];
              fileResult.forEach((upload, index) => {
                uploads.push({
                  fileId: upload.fileId || "",
                  type: "file",
                  name: upload.name,
                  status: "done",
                  uid: index,
                  url: upload.path || "",
                });
              });
              item.files = uploads;
            });
          that.workflow.duBanHistory = datas;
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
/deep/ .ant-modal-body {
  padding: 0;
}

.body {
  padding: 4px;

  .left {
    float: right;
    width: 300px;
    padding: 10px;
    margin: 0 0 10px 4px;
    background: #fff;
  }

  .right {
    overflow: auto;
  }

  .eip-drawer-body {
    background-color: rgb(245, 245, 249);
  }

  .form {
    width: 98%;
    margin: 0 auto;
    border-width: 1px;
    border-style: solid;
    background-color: rgba(255, 255, 255, 1);
    border-color: rgba(233, 233, 233, 1);
    border-radius: 5px;
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    font-family: "微软雅黑", sans-serif;
    font-weight: 400;
    font-style: normal;
    text-align: left;
    line-height: 20px;
    padding: 30px 10px;
    margin-top: 10px;
  }
}

/deep/ table .ant-form-item {
  margin: 0 !important;
}

.invitationReadApproveDetail {
  padding: 10px;
  background-color: rgba(242, 242, 242, 1);
  box-sizing: border-box;
  border-width: 1px;
  border-style: solid;
  border-color: rgba(242, 242, 242, 1);
  border-radius: 10px;
  -moz-box-shadow: none;
  -webkit-box-shadow: none;
  box-shadow: none;
  font-weight: 400;
  font-style: normal;
  text-align: left;
  line-height: 20px;
}

.workflowCard:hover {
  box-shadow: 0 2px 10px rgb(0 0 0 / 8%)
}

/deep/.ant-timeline-item-content {
  margin: 0 0 0 30px !important
}

.pointerItem {
  background-color: #ddd;
  border-radius: 50%;
  flex-shrink: 0;
  height: 11px;
  width: 11px;
}

.pointerItem.active {
  background-color: #fff;
  box-shadow: 0 0 10px 1px #2196f3;
  flex: 0 0 20px;
  height: 20px;
  margin-top: -6px;
  position: relative;
  width: 20px;
}

.pointerItem.active:after {
  background: #2196f3;
  border-radius: 50%;
  content: "";
  height: 16px;
  left: 2px;
  position: absolute;
  top: 2px;
  width: 16px;
}
</style>
